package com.koron.operation.classes.shift.bean.param;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.koron.operation.classes.schedule.bean.po.ClassesStaff;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;

/**
 * 人员调整参数
 * @author jzp
 * @since 2021/10/27
 */
@Data
@ApiModel(value = "人员调整参数", description = "ClassesAdjustParam")
public class ClassesAdjustParam {

    /**
     * 班次id
     */
    @ApiModelProperty("班次id")
    private String shiftId;

    /**
     * 调整时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    @ApiModelProperty("调整时间")
    private Date adjustTime;

    /**
     * 调整前人员信息
     */
    @ApiModelProperty("调整前人员信息，可为空")
    private List<ClassesStaff> beforeStaffs;

    /**
     * 调整后人员信息
     */
    @ApiModelProperty("调整后人员信息")
    private List<ClassesStaff> afterStaffs;

    /**
     * 调整原因
     */
    @ApiModelProperty("调整原因")
    private String cause;

    public String toStaffStr(List<ClassesStaff> staffs) {
        StringBuilder str = new StringBuilder();
        if (CollectionUtils.isEmpty(staffs)) {
            return "";
        }

        for (ClassesStaff staff : staffs) {
            str.append(staff.getStaffName());
            if ("0".equals(staff.getType())) {
                str.append("|");
            } else {
                str.append(",");
            }
        }
        return StrUtil.strip(str, ",");
    }
}
